package org.clever.dropwizard;

import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import lombok.extern.slf4j.Slf4j;
import org.clever.dropwizard.config.HelloWorldConfiguration;
import org.clever.dropwizard.controller.HelloWorldController;
import org.clever.dropwizard.health.TemplateHealthCheck;

/**
 * 应用启动类
 * Created by lzw on 2017/2/25.
 */
@Slf4j
public class StartApp extends Application<HelloWorldConfiguration> {

    public static void main(String[] args) throws Exception {
        new StartApp().run(args);
        log.info("### 启动成功 --------");
    }

    @Override
    public String getName() {
        return "DropwizardDemo";
    }

    @Override
    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
    }

    @Override
    public void run(HelloWorldConfiguration configuration, Environment environment) {
        log.info("### configuration --> {}", configuration);
        final HelloWorldController resource = new HelloWorldController(configuration.getTemplate(), configuration.getDefaultName());
        environment.jersey().register(resource);
        final TemplateHealthCheck healthCheck = new TemplateHealthCheck(configuration.getTemplate());
        environment.healthChecks().register("template", healthCheck);
    }
}
